
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue'),
  },
  {
    path: '/home/search',
    name: 'homeSearch',
    component: () => import(/* webpackChunkName: "homeSearch" */ '../views/home/search/index.vue')
  },
  {
    path: '/home/list',
    name: 'homeList',
    component: () => import(/* webpackChunkName: "homeList" */ '../views/home/list/index.vue')
  },
  {
    path: '/home/product',
    name: 'homeProduct',
    component: () => import(/* webpackChunkName: "homeProduct" */ '../views/home/product/index.vue')
  },
  {
    path: '/home/location',
    name: 'homeLocation',
    component: () => import(/* webpackChunkName: "homeLocation" */ '../views/home/location/index.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "cart" */ '../views/cart/index.vue')
  },
  {
    path: '/cart/order',
    name: 'cartOrder',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "cartOrder" */ '../views/cart/order/index.vue')
  },
  {
    path: '/cart/order/address',
    name: 'cartOrderAddress',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "cartOrderAddress" */ '../views/cart/order/address/index.vue')
  },
  {
    path: '/cart/order/address/edit/:id',
    name: 'cartOrderAddressEdit',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "cartOrderAddressEdit" */ '../views/cart/order/address/edit/index.vue')
  },
  {
    path: '/cart/order/address/addAddress',
    name: 'cartOrderAddressaddAddress',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "cartOrderAddressaddAddress" */ '../views/cart/order/address/edit/index.vue')
  },
  {
    path: '/category',
    name: 'category',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "category" */ '../views/category/index.vue')
  },
  {
    path: '/category/list',
    name: 'categoryList',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "categoryList" */ '../views/category/list/index.vue')
  },
  {
    // 动态路由传递的参数
    path: '/category/list/info/:id',
    name: 'categoryListInfo',
    component: () => import(/* webpackChunkName: "info" */ '../views/category/list/info/index.vue')
  },
  {
    path: '/topic',
    name: 'topic',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/topic/index.vue')
  },
  {
    path: '/topic/detail',
    name: 'topicDetail',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "topicDetail" */ '../views/topic/detail/index.vue')
  },
  {
    path: '/user',
    name: 'user',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "user" */ '../views/user/index.vue')
  },
  {
    path: '/user/collect',
    name: 'userCollect',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "userCollect" */ '../views/user/collect/index.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router
